package deadlock

import "fmt"

func mux(
		decodeMux		chan DEMU,
		aluMux			chan ALMU,
		muxRegister		chan MURE) {
	for{
		demu :=<- decodeMux
		fmt.Println("[MUX] DEMU <-- DECODE")
		almu :=<-aluMux
		fmt.Println("[MUX] ALMU <-- ALU")
		if almu.CANCELLED == false{
			switch demu.MUX_UNIT{
				case ALU:
					switch demu.MUX_COMMAND{
						case RRS_RRT_WRD:
							fmt.Println("[MUX] ALMU <-- ALU (cmd: RRS_RRT_WRD unit: ALU)")
							muxRegister<-MURE{WRITE:almu.EXEC_TO_REG, CANCELLED: false}
							fmt.Println("[MUX] MURE --> REGISTER")
							
						case RRS_WRT:
							fmt.Println("[MUX] ALMU <-- ALU (cmd: RRS_WRT unit: ALU)")
							muxRegister<-MURE{WRITE:almu.EXEC_TO_REG, CANCELLED: false}
							fmt.Println("[MUX] MURE --> REGISTER")
					}
			}
		}
	}
}